///**
// * @projectName: dataAccessFactory
// * @author: 小飞
// * @description: TODO
// * @date: 2024/4/29 21:06
// * @version: 1.0
// */
//package com.cqie.gateway.filter;
//
//import com.cqie.dataAccessFactory.constant.TokenConstant;
//import com.cqie.dataAccessFactory.constant.User;
//import com.cqie.dataAccessFactory.exception.BaseException;
//import com.cqie.gateway.config.RedisUtil;
//import com.cqie.openFeign.UserFeignClient;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.core.annotation.Order;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//import java.util.List;
//
//
//@Order(-1)
//@Component
//@RequiredArgsConstructor
//@Slf4j
//public class AuthorizeFilter implements GlobalFilter {
//
//
//
//
//    @Override
//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//        log.info("开始进入全局拦截器.....");
//        ServerHttpRequest request = exchange.getRequest();
//        String path = request.getURI().getPath();
//        HttpHeaders headers = request.getHeaders();
//        String token = headers.getFirst("token");
//        if ("/api/admin/user/login".equals(path)){
//          if (token == null || token.isEmpty()){
//              return chain.filter(exchange);
//          }else {
//              throw new BaseException("登录不应包含token");
//          }
//        }else {
//            if (token == null || token.isEmpty()){
//                exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
//                return exchange.getResponse().setComplete();
//            }
//        }
//        User user = (User) redisUtil.getRedisObject(TokenConstant.TOKEN_HEADER_SECRET +token);
//        if (user != null){
//            return chain.filter(exchange);
//        }else {
//            exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
//            return exchange.getResponse().setComplete();
//        }
//    }
//
//    public boolean getPermissionList(List<String> permissionList,String path){
//        if ("/api/**/getPageDatabase".equals(path)){
//            return permissionList.contains("admin");
//        }
//        return false;
//    }
//}
